{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Perfect Squares"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #breadth-first-search #math #dynamic-programming"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #广度优先搜索 #数学 #动态规划"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numSquares"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #完全平方数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数 <code>n</code> ，返回 <em>和为 <code>n</code> 的完全平方数的最少数量</em> 。</p>\n",
    "\n",
    "<p><strong>完全平方数</strong> 是一个整数，其值等于另一个整数的平方；换句话说，其值等于一个整数自乘的积。例如，<code>1</code>、<code>4</code>、<code>9</code> 和 <code>16</code> 都是完全平方数，而 <code>3</code> 和 <code>11</code> 不是。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例&nbsp;1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>n = <code>12</code>\n",
    "<strong>输出：</strong>3 \n",
    "<strong>解释：</strong><code>12 = 4 + 4 + 4</code></pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>n = <code>13</code>\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong><code>13 = 4 + 9</code></pre>\n",
    "&nbsp;\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [perfect-squares](https://leetcode.cn/problems/perfect-squares/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [perfect-squares](https://leetcode.cn/problems/perfect-squares/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['12', '13']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        \"\"\"BFS\"\"\"\n",
    "        q = [(n, 0)]\n",
    "        s = set()\n",
    "        while q:\n",
    "            num, lev = q.pop(0)\n",
    "            for i in range(1, int(pow(num, 0.5)) + 1):\n",
    "                num_new = num - i*i\n",
    "                if num_new not in s:\n",
    "                    s.add(num_new)\n",
    "                    if num_new == 0:\n",
    "                        return lev+1\n",
    "                    q.append((num_new, lev+1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: 'int') -> 'int':\n",
    "        h = {0: 0}\n",
    "        def backtrack(n, h, cur, cur_min):\n",
    "            # print(\"call bt \", n)\n",
    "            if cur >= cur_min[0]:\n",
    "                return\n",
    "            n_sqrt = int(n ** 0.5)\n",
    "            if n == n_sqrt ** 2:\n",
    "                cur = cur + 1\n",
    "                cur_min[0] = cur\n",
    "                return\n",
    "            for i in range(n_sqrt, 0, -1):\n",
    "                if n - i ** 2 in h.keys():\n",
    "                    cur_new = cur + h[n - i ** 2]\n",
    "                    if cur_new < cur_min[0]:\n",
    "                        cur_min[0] = cur_new\n",
    "                else:\n",
    "                    if n / (i ** 2) > cur_min[0] - cur:\n",
    "                        break\n",
    "                    backtrack(n - i ** 2, h, cur + 1, cur_min)\n",
    "        \n",
    "        cur_min = [n]\n",
    "        backtrack(n, h, 0, cur_min)\n",
    "        # print(cur_min)\n",
    "        return cur_min[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: 'int') -> 'int':\n",
    "        dp = [5] * (n+1)\n",
    "        dp[0] = 0\n",
    "        dp[1] = 1\n",
    "        for i in range(2, n+1):\n",
    "            for j in range(1, int(math.sqrt(i))+1):\n",
    "                dp[i] = min(dp[i], dp[i-j*j] + 1)\n",
    "        return dp[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\"\"\"\n",
    "Lagrange 四平方定理： 任何一个正整数都可以表示成不超过四个整数的平方之和。\n",
    "那么我们这个问题的解法就变得很简单了，我们的结果只有1,2,3,4，四种可能。\n",
    "\n",
    "另外还有一个非常重要的推论\n",
    "\n",
    "满足四数平方和定理的数n（这里要满足由四个数构成，小于四个不行），必定满足 n=4^a*(8b+7)\n",
    "\n",
    "根据这个重要的推论，我们可以非常迅速的写出这样的代码。\n",
    "\n",
    "我们首先将输入的n迅速缩小。然后我们再判断，这个缩小后的数是否可以通过两个平方数的和或一个平方数组成，不能的话我们返回3，能的话我们返回平方数的个数。\n",
    "\n",
    "\"\"\"\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        while n % 4 == 0:\n",
    "            n /= 4\n",
    "        \n",
    "        if n % 8 == 7: \n",
    "            return 4\n",
    "\n",
    "        a = 0\n",
    "        while a**2 <= n:\n",
    "            b = int((n - a**2)**0.5)\n",
    "            if a**2 + b**2 == n:\n",
    "                return (not not a) + (not not b)\n",
    "\n",
    "            a += 1\n",
    "\n",
    "        return 3\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        while n % 4 == 0:\n",
    "            n /= 4\n",
    "        if n % 8 == 7:\n",
    "            return 4\n",
    "        a = 0\n",
    "        while a * a <= n:\n",
    "            b = int((n - a * a) ** 0.5)\n",
    "            if a * a + b * b == n:\n",
    "                return (not not a) + (not not b)\n",
    "            a += 1\n",
    "        return 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: 'int') -> 'int':\n",
    "        while n % 4 == 0:\n",
    "            n //= 4\n",
    "        #如果n除以8余7的话，那么n一定由4个平方数组成\n",
    "        if n % 8 == 7:\n",
    "            return 4\n",
    "        dynamic = [x for x in range(n + 1)]\n",
    "        squares = [i * i for i in range(1, int(n**0.5) + 1)]\n",
    "        for item in squares:\n",
    "            dynamic[item] = 1\n",
    "        for i in range(1, n + 1):\n",
    "            for sq in squares:\n",
    "                if i + sq <= n:\n",
    "                    dynamic[i + sq] = min(dynamic[i] + 1, dynamic[i + sq])\n",
    "        return dynamic[-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        import math\n",
    "        p = [i for i in range(n+1)]\n",
    "        for i in range(1,n+1):\n",
    "            if i**0.5-math.floor(i**0.5) == 0:\n",
    "                p[i] = 1\n",
    "                continue\n",
    "            for j in range(1, math.floor(i**0.5)+1):\n",
    "                p[i] = min(p[i], p[j*j]+p[i-j*j])\n",
    "        return p[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: 'int') -> 'int':\n",
    "        dynamic = [x for x in range(n + 1)]\n",
    "        squares = [i * i for i in range(1, int(n**0.5) + 1)]\n",
    "        for item in squares:\n",
    "            dynamic[item] = 1\n",
    "        for i in range(1, n + 1):\n",
    "            for sq in squares:\n",
    "                if i + sq <= n:\n",
    "                    dynamic[i + sq] = min(dynamic[i] + 1,dynamic[i + sq])\n",
    "        return dynamic[-1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: 'int') -> 'int':\n",
    "        queue = []\n",
    "        visited = set()\n",
    "        step = 1\n",
    "        queue.append(0)\n",
    "        visited.add(0)\n",
    "        while queue:\n",
    "            size = len(queue)\n",
    "            for _ in range(size):\n",
    "                cur = queue[0]\n",
    "                for i in range(1, n):\n",
    "                    new = cur + i * i\n",
    "                    if new > n:\n",
    "                        break\n",
    "                    elif new == n:\n",
    "                        return step\n",
    "                    if new not in visited:\n",
    "                        visited.add(new)\n",
    "                        queue.append(new)\n",
    "                queue.pop(0)\n",
    "            step += 1\n",
    "        return 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: 'int') -> 'int':\n",
    "        queue = []\n",
    "        visited = set()\n",
    "        step = 1\n",
    "        queue.append(0)\n",
    "        visited.add(0)\n",
    "        while queue:\n",
    "            size = len(queue)\n",
    "            for _ in range(size):\n",
    "                cur = queue[0]\n",
    "                for i in range(1, n):\n",
    "                    new = cur + i * i\n",
    "                    if new > n:\n",
    "                        break\n",
    "                    elif new == n:\n",
    "                        return step\n",
    "                    if new not in visited:\n",
    "                        visited.add(new)\n",
    "                        queue.append(new)\n",
    "                queue.pop(0)\n",
    "            step += 1\n",
    "        return 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        if n < 2:\n",
    "            return n\n",
    "        lst = []\n",
    "        i = 1\n",
    "        while i * i <= n:\n",
    "            lst.append( i * i )\n",
    "            i += 1\n",
    "        cnt = 0\n",
    "        toCheck = {n}\n",
    "        while toCheck:\n",
    "            cnt += 1\n",
    "            temp = set()\n",
    "            for x in toCheck:\n",
    "                for y in lst:\n",
    "                    if x == y:\n",
    "                        return cnt\n",
    "                    if x < y:\n",
    "                        break\n",
    "                    temp.add(x-y)\n",
    "            toCheck = temp\n",
    "\n",
    "        return cnt\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    \n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        \n",
    "        from collections import deque\n",
    "        \n",
    "        res = 1\n",
    "        d = deque()\n",
    "        l = set()\n",
    "        for i in range(1, int(n ** 0.5) + 1):\n",
    "            if i * i == n:\n",
    "                return res\n",
    "            l.add(n - i*i)\n",
    "        d.append(l)\n",
    "            \n",
    "        \n",
    "        while d:\n",
    "            n_list = d.popleft()\n",
    "            l = set()\n",
    "            for n in n_list:\n",
    "                for i in range(1, int(n ** 0.5) + 1):\n",
    "                    if i * i == n:\n",
    "                        return res + 1\n",
    "                    l.add(n - i*i)\n",
    "            d.append(l)\n",
    "            res += 1\n",
    "        \n",
    "        \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        import math\n",
    "        Big = int(math.sqrt(n))\n",
    "        if n<2:\n",
    "            return n\n",
    "        path = [i**2 for i in range(1,Big+1)]\n",
    "        number = 0\n",
    "        target = {n}\n",
    "        while target:\n",
    "            number += 1 \n",
    "            for x in list(target):\n",
    "                for y in path:\n",
    "                    if x-y==0:\n",
    "                        return number\n",
    "                    if y>x:\n",
    "                        break\n",
    "                    target.add(x-y)\n",
    "                target.remove(x)        \n",
    "        return number\n",
    "                    \n",
    "            \n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import collections\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        Q = collections.deque([n])\n",
    "        visited, level = set(), 0\n",
    "        while Q:\n",
    "            for i in range(len(Q)):\n",
    "                n = Q.popleft()\n",
    "                \n",
    "                if n == 0:\n",
    "                    return level\n",
    "                for i in range(1, int(n**0.5)+1):\n",
    "                    val = n - i**2\n",
    "                    if val in visited:\n",
    "                        continue\n",
    "                    Q.append(val)\n",
    "                    visited.add(val)\n",
    "            level += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        init, dic, loop, temp, cnddt = 1, {}, 1, 1, []\n",
    "        while temp <= n:\n",
    "            cnddt.append(temp)\n",
    "            dic[temp] = 1\n",
    "            init += 1\n",
    "            temp = init ** 2\n",
    "        while n not in dic:\n",
    "            loop += 1\n",
    "            for key in list(dic.keys()):\n",
    "                for num in cnddt:\n",
    "                    temp = key + num\n",
    "                    if temp == n:\n",
    "                        return loop\n",
    "                    if temp not in dic and temp < n:\n",
    "                        dic[temp] = loop\n",
    "                    elif temp > n:\n",
    "                        break\n",
    "        return dic[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        temp = int(n**0.5)\n",
    "        if temp**2 == n: return 1\n",
    "        squs = [x**2 for x in range(1, temp + 1)]\n",
    "        nums = [n - x for x in squs]\n",
    "        i = 2\n",
    "        while True:\n",
    "            temp = set()\n",
    "            for x in nums:\n",
    "                for y in squs:\n",
    "                    if x == y:\n",
    "                        return i\n",
    "                    elif x > y:\n",
    "                        temp.add(x - y)\n",
    "            i += 1\n",
    "            nums = temp\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    \n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        q = []\n",
    "        q.append((n, 1))\n",
    "        visited = {}\n",
    "        visited[n] = 1\n",
    "        while q:\n",
    "            k, res = q.pop(0)\n",
    "            i = 1\n",
    "            m = k-i*i\n",
    "            while m >= 0:\n",
    "                if m == 0:\n",
    "                    return res\n",
    "                else:\n",
    "                    if m not in visited:\n",
    "                        q.append((m, res+1))\n",
    "                        visited[m] = 1\n",
    "                    i += 1\n",
    "                    m = k-i*i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        \"\"\"\n",
    "        :type n: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        import collections\n",
    "        visited = [False]*(n+1)\n",
    "        visited[n]=True\n",
    "        q = collections.deque([[n,0]])\n",
    "        while len(q)!=0:\n",
    "            num,step = q.popleft()\n",
    "            i=1\n",
    "            while num-i*i>=0:\n",
    "                if num-i*i==0:\n",
    "                    return step+1\n",
    "                if visited[num-i*i]==False:\n",
    "                    visited[num-i*i]=True\n",
    "                    q.append([num-i*i,step+1])\n",
    "                i+=1\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        if n==0:\n",
    "            return 0\n",
    "        output = [9999999]*(n+1)\n",
    "        output[0] = 0\n",
    "        output[1] = 1\n",
    "        for i in range(2,n+1):\n",
    "            j = 1\n",
    "            while(j*j<=i):\n",
    "                output[i] = min(output[i],output[i-j*j]+1)\n",
    "                j = j+1\n",
    "        \n",
    "        return output[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        if n<=0:\n",
    "            return None\n",
    "        MAX=2<<31-1\n",
    "        dp=[MAX]*(n+1)\n",
    "        dp[0]=0\n",
    "        for i in range(1,n+1):\n",
    "            for j in range(1,int(i**0.5)+1):\n",
    "                dp[i]=min(dp[i],dp[i-j*j]+1)\n",
    "        return dp[-1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        while n%4 == 0:\n",
    "            n//=4\n",
    "        if n%8 == 7:\n",
    "            return 4\n",
    "        a = 0\n",
    "        while a**2 <= n:\n",
    "            b = int((n-a**2)**0.5)\n",
    "            if a**2 + b**2 == n:\n",
    "                return (not not a) + (not not b)\n",
    "            a+=1\n",
    "        return 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        while n % 4 == 0: \n",
    "            n /= 4 \n",
    "        if n % 8 == 7: \n",
    "            return 4 \n",
    "        a = 0 \n",
    "        while a**2 <= n: \n",
    "            b = int((n - a**2)**0.5) \n",
    "            if a**2 + b**2 == n: \n",
    "                return (not not a) + (not not b) \n",
    "            a += 1 \n",
    "        return 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        dp=[0]*(n+1)\n",
    "        for i in range(1,n+1):\n",
    "            dp[i]=i\n",
    "            j=1\n",
    "            while j*j<=i:\n",
    "                dp[i]=min(dp[i],dp[i-j*j]+1)\n",
    "                j+=1\n",
    "        return dp[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        dp=[i for i in range(n+1)]\n",
    "        for i in range(2,n+1):\n",
    "            for j in range (1,int(i**0.5)+1):\n",
    "                dp[i]=min(dp[i],dp[i-j*j]+1)\n",
    "        return dp[-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "\n",
    "        def is_divided_by(n, count):\n",
    "            \"\"\"\n",
    "                return: true if \"n\" can be decomposed into \"count\" number of perfect square numbers.\n",
    "                e.g. n=12, count=3:  true.\n",
    "                     n=12, count=2:  false\n",
    "            \"\"\"\n",
    "            if count == 1:\n",
    "                return n in square_nums\n",
    "            \n",
    "            for k in square_nums:\n",
    "                if is_divided_by(n - k, count - 1):\n",
    "                    return True\n",
    "            return False\n",
    "\n",
    "        square_nums = set([i * i for i in range(1, int(math.sqrt(n))+1)])\n",
    "    \n",
    "        for count in range(1, n+1):\n",
    "            if is_divided_by(n, count):\n",
    "                return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n):\n",
    "        dp = [n+1] * (n + 1)\n",
    "        dp[0] = 0\n",
    "\n",
    "        for i in range(1, n + 1):\n",
    "            for j in range(1, n+1):\n",
    "                j2 = j*j\n",
    "                if j2 > n:\n",
    "                    break\n",
    "                if i >= j2:\n",
    "                    dp[i] = min(dp[i - j2] + 1, dp[i])\n",
    "\n",
    "        return dp[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "      \n",
    "        def b(x):\n",
    "            while x%4==0:\n",
    "                x/=4\n",
    "            return x%8==7\n",
    "        def a(x):\n",
    "            y=int(sqrt(x))\n",
    "            return x==y*y\n",
    "        if a(n):\n",
    "            return 1\n",
    "        \n",
    "        if b(n):\n",
    "            return 4\n",
    "        i=0\n",
    "        while i*i <=n:\n",
    "            j=n-i*i\n",
    "            if a(j):\n",
    "                return 2\n",
    "            i+=1 \n",
    "        return 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from math import *\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        self.result = 10000\n",
    "        self.deep_search(n, 0, int(sqrt(n)))\n",
    "        return self.result\n",
    "\n",
    "    def deep_search(self, n, count, num):\n",
    "        if n == 0:\n",
    "            self.result = min(self.result, count)\n",
    "            return\n",
    "        if count+1 >= self.result or num < 1:\n",
    "            return\n",
    "        new_n = n - num ** 2\n",
    "        self.deep_search(new_n, count+1, int(sqrt(new_n)))\n",
    "        self.deep_search(n, count, num-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        dp = [float('inf') for _ in range(n+1)]\n",
    "        dp[0] = 0\n",
    "        for i in range(n+1):\n",
    "            j = 1\n",
    "            while i+j*j<=len(dp)-1:\n",
    "                dp[i+j*j] = min(dp[i+j*j],dp[i]+1)\n",
    "                j += 1\n",
    "        return dp[-1]\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        dp = [float('inf') for _ in range(n+1)]\n",
    "        dp[0] = 0\n",
    "        for i in range(n+1):\n",
    "            j = 1\n",
    "            while i+j*j<=len(dp)-1:\n",
    "                dp[i+j*j] = min(dp[i+j*j],dp[i]+1)\n",
    "                j += 1\n",
    "        return dp[-1]\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from functools import lru_cache\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    # def numSquares(self, n: int) -> int:\n",
    "    #     num = (int(n ** 0.5) + 1)\n",
    "\n",
    "    #     @lru_cache\n",
    "    #     def dp(i, c):\n",
    "    #         if c == 0:\n",
    "    #             return 0\n",
    "    #         if i == 0:\n",
    "    #             return float('inf')\n",
    "    #         if i > c:\n",
    "    #             return dp(i - 1, c)\n",
    "    #         res1 = dp(i, c - i * i) + 1\n",
    "    #         res2 = dp(i - 1, c)\n",
    "    #         return min(res1, res2)\n",
    "\n",
    "    #     return dp(num, n)\n",
    "    \n",
    "    # def numSquares(self, n: int) -> int:\n",
    "    #     num = int(n ** 0.5) + 1\n",
    "    #     dp = [[float('inf')] * (n + 1) for _ in range(num + 1)]\n",
    "    #     # 列表示剩余的数字，\n",
    "    #     for i in range(num + 1):\n",
    "    #         dp[i][0] = 0\n",
    "\n",
    "    #     for c in range(1, n + 1):\n",
    "    #         for i in range(num + 1):\n",
    "    #             if i > c or i * i > c:\n",
    "    #                 dp[i][c] = dp[i - 1][c]\n",
    "    #             else:\n",
    "    #                 dp[i][c] = min(dp[i][c - i * i] + 1, dp[i - 1][c])\n",
    "    #     return dp[num][n]\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        nums = [i**2 for i in range(int(n ** 0.5) + 1)]\n",
    "        dp = [float('inf')] * (n + 1)\n",
    "        # 列表示剩余的数字，\n",
    "        dp[0] = 0\n",
    "\n",
    "        for c in range(1, n + 1):\n",
    "            for num in nums:\n",
    "                if num <=c:\n",
    "                    dp[c] = min(dp[c - num] + 1, dp[c])\n",
    "        return dp[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        DP = [float('inf')]*(n+1)\n",
    "        DP[0] = 0\n",
    "        for i in range(0,n+1):\n",
    "            for c in range(int(i**0.5)+1):\n",
    "                if DP[i-c*c]+1<=DP[i]:\n",
    "                    DP[i] = DP[i-c*c]+1\n",
    "        return DP[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        dp = [0.0] + [float('inf')] * n\n",
    "        i = 1\n",
    "        while i * i <= n:\n",
    "            for j in range(i * i, n + 1):\n",
    "                dp[j] = min(dp[j], dp[j - i * i] + 1)\n",
    "            i += 1\n",
    "        # print(dp)\n",
    "        dp[n] = -1 if dp[n] > n else dp[n]\n",
    "        return int(dp[n])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        #一维dp就可以做 完全背包问题\n",
    "        temp=int(math.sqrt(n))\n",
    "        nums=[i*i for i in range(1,temp+1) ]\n",
    "        dp=[n+1]*(n+1)\n",
    "        dp[0]=0\n",
    "        dp[1]=1\n",
    "        for i in range(len(nums)):\n",
    "            for j in range(nums[i],n+1):\n",
    "                dp[j]=min(dp[j-nums[i]]+1,dp[j])\n",
    "        print(dp)\n",
    "        return dp[-1]\n",
    "\n",
    "\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        \"\"\" bfs \"\"\"\n",
    "        perfect_square_nums = [i ** 2 for i in range(1, int(n ** 0.5)+1)]\n",
    "        visited_i = set()\n",
    "        queue = deque([n])\n",
    "        nums_count = 0\n",
    "        while queue:\n",
    "            for _ in range(len(queue)):\n",
    "                residue = queue.popleft()\n",
    "                if residue == 0:\n",
    "                    return nums_count\n",
    "                \n",
    "                for s in perfect_square_nums:\n",
    "                    diff = residue - s\n",
    "                    # prune\n",
    "                    if diff >= 0 and diff not in visited_i:\n",
    "                        queue.append(diff)\n",
    "                        visited_i.add(diff)\n",
    "            nums_count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        cache = dict(zip([k for k in range(n+1)], [k for k in range(n+1)]))\n",
    "        s = 2\n",
    "        while s**2 <= n:\n",
    "            m = s**2\n",
    "            for i in range(n-m+1):\n",
    "                if cache[i+m] > cache[i] + 1:\n",
    "                    cache[i+m] = cache[i] + 1\n",
    "            s += 1\n",
    "        return cache[n]\n",
    "                \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        from collections import deque\n",
    "        deq=deque()\n",
    "        visited=set()\n",
    "        \n",
    "        deq.append((n,0))\n",
    "        while deq:\n",
    "            number,step=deq.popleft()\n",
    "            targets=[number-i*i for i in range(1,int(number**0.5)+1)]\n",
    "            for target in targets:\n",
    "                if target==0:return step+1\n",
    "                if target not in visited:\n",
    "                    deq.append((target,step+1))\n",
    "                    visited.add(target)\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Node:\n",
    "    def __init__(self, value, step=0):\n",
    "        self.value = value\n",
    "        self.step = step\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        q = [Node(n)]\n",
    "        visited = set()\n",
    "        visited.add(n)\n",
    "\n",
    "        while q:\n",
    "            vertex = q.pop(0)\n",
    "            residuals = [vertex.value - n*n for n in range(1, int(vertex.value ** .5)+1)]\n",
    "            for i in residuals:\n",
    "                new_vertex = Node(i, vertex.step+1)\n",
    "                if i == 0:\n",
    "                    return new_vertex.step\n",
    "                if i not in visited:\n",
    "                    visited.add(i)\n",
    "                    q.append(new_vertex)\n",
    "        return -1\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class node:\n",
    "    def __init__(self,value,step=0):\n",
    "        self.value = value\n",
    "        self.step = step\n",
    "    def __str__(self):\n",
    "        return '<value:{}, step:{}>'.format(self.value,self.step)\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        queue = [node(n)]\n",
    "        visited = set([node(n).value])\n",
    "        \n",
    "        while queue:\n",
    "            vertex = queue.pop(0)\n",
    "            residuals = [vertex.value - n*n for n in range(1,int(vertex.value**.5)+1)]\n",
    "            for i in residuals:\n",
    "                new_vertex = node(i, vertex.step+1)\n",
    "                if i==0:                   \n",
    "                    return new_vertex.step\n",
    "                    \n",
    "                elif i not in visited:\n",
    "                    queue.append(new_vertex)\n",
    "                    visited.add(i)\n",
    "                                        \n",
    "        return -1\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        @lru_cache(None)\n",
    "        def dfs(n):\n",
    "            if n <= 1:\n",
    "                return n \n",
    "            ans = inf\n",
    "            for i in range(int(sqrt(n)),0,-1):\n",
    "                ans = min(ans,dfs(n % (i*i)) + n // (i*i))\n",
    "            return ans\n",
    "        return dfs(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        qun = [[0,0]]\n",
    "        has = set()\n",
    "\n",
    "        while qun:\n",
    "            val,l = qun.pop(0)\n",
    "            if val==n:\n",
    "                return l\n",
    "            i=1\n",
    "            while val+i**2<n:\n",
    "                if val+i*i not in has:\n",
    "                    qun.append([val+i*i,l+1])\n",
    "                    has.add(val+i*i)\n",
    "                i+=1\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # dp = [i for i in range(n+1)]\n",
    "        # for i in range(1, n+1):\n",
    "        #     j=1\n",
    "        #     while j*j<n+1:\n",
    "        #         dp[i] = min(dp[i],dp[i-j*j]+1)\n",
    "        #         j+=1\n",
    "        # return dp[-1]\n",
    "\n",
    "        queue = [(0, 0)]\n",
    "        hash = set()\n",
    "        while queue:\n",
    "            val, level = queue.pop(0)\n",
    "            if val == n:\n",
    "                return level\n",
    "            i = 1\n",
    "            while val + i*i <= n:\n",
    "                if val + i*i not in hash:  \n",
    "                    queue.append((val+i*i, level+1))\n",
    "                    hash.add(val+i*i)\n",
    "                i += 1 \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "\n",
    "        if not n: return 0\n",
    "        que = [n]\n",
    "        visited = set()\n",
    "        depth = 0\n",
    "        while que:\n",
    "            depth += 1\n",
    "            for _ in range(len(que)):\n",
    "                tmp = que.pop(0)\n",
    "                for i in range(1, int(n**0.5)+1):\n",
    "                    x = tmp - i*i\n",
    "                    if x == 0:\n",
    "                        return depth\n",
    "                    if x not in visited:\n",
    "                        que.append(x)\n",
    "                        visited.add(x)\n",
    "        return depth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        # BFS\n",
    "        queue = [(n, 0)] \n",
    "        seen = {n}\n",
    "        while queue:\n",
    "            cur, step = queue.pop(0)\n",
    "            residuals = [x ** 2 for x in range(1, int(n ** 0.5) + 1)]\n",
    "            for i in range(len(residuals)):\n",
    "                if cur - residuals[i] == 0:\n",
    "                    return step + 1\n",
    "                if cur - residuals[i] not in seen:\n",
    "                    queue.append((cur - residuals[i], step + 1))\n",
    "                    seen.add(cur - residuals[i])\n",
    "        return -1\n",
    "\n",
    "        # https://leetcode-cn.com/problems/coin-change/   基本一模一样\n",
    "        # BFS  比DP速度快多了\n",
    "        queue = [(n, 0)]\n",
    "        seen = {n}  # 只记录n就行了，因为是BFS 所以最先出现的长度肯定小于等于后来出现的\n",
    "        # seen = {(n, 0)}\n",
    "        while queue:\n",
    "            cur, step = queue.pop(0)\n",
    "            residuals = [x ** 2 for x in range(1, int(cur ** 0.5) + 1)]\n",
    "            for i in residuals:\n",
    "                new_cur = cur - i\n",
    "                new_step = step + 1\n",
    "                if new_cur == 0:\n",
    "                    return new_step\n",
    "                if new_cur not in seen:\n",
    "                    queue.append((new_cur, new_step))\n",
    "                    seen.add(new_cur)\n",
    "        return -1\n",
    "\n",
    "        # 递归dp  6000ms\n",
    "        residuals = [x ** 2 for x in range(1, int(n ** 0.5) + 1)]\n",
    "        @functools.lru_cache(None)\n",
    "        def dp(state):\n",
    "            if state == 0:\n",
    "                return 0\n",
    "            res = float(\"inf\")\n",
    "            for i in residuals:\n",
    "                if i > state:\n",
    "                    return res \n",
    "                if i <= state:\n",
    "                    res = min(res, 1 + dp(state - i))\n",
    "            return res\n",
    "        return dp(n)\n",
    "        \n",
    "\n",
    "        # DP table\n",
    "        # https://leetcode-cn.com/problems/perfect-squares/solution/chao-zhi-bai-kao-zui-jiang-xiao-xue-sheng-du-neng-/\n",
    "        dp = [float(\"inf\") for i in range(n+1)]\n",
    "        dp[0] = 0\n",
    "        for i in range(1, n + 1):\n",
    "            for j in range(1, int(i**0.5) + 1):\n",
    "                dp[i] = min(dp[i], dp[i - j*j] + 1)  # dpi表示i需要多少个平方数表示   其实就是N = 1、2、4、9... + N’ 一个数=一个平方数+另一个数\n",
    "        return dp[-1]\n",
    "        \n",
    "\n",
    "        '''\n",
    "        # DFS 超时\n",
    "        self.res = float(\"inf\")\n",
    "        self.ans = []\n",
    "        def backtrack(track):\n",
    "            if len(track) >= self.res: return\n",
    "            if sum(track) == n:\n",
    "                self.res = min(self.res, len(track))\n",
    "                if self.res == len(track):\n",
    "                    self.ans = track[:]\n",
    "                return\n",
    "            diff = n - sum(track)\n",
    "            for i in range(int(sqrt(diff)), 0, -1):\n",
    "                track.append(i ** 2)\n",
    "                backtrack(track)\n",
    "                track.pop()\n",
    "        backtrack([])\n",
    "        # print(self.res, self.ans)\n",
    "        return self.res\n",
    "        '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        \n",
    "        q = collections.deque([n])#双向队列\n",
    "        step = 0#步数=最少数量=树的深度，广度优先遍历=一层层的遍历\n",
    "        seen = set() # 记录已访问过的顶点，避免重复求解子问题\n",
    "        seen.add(n)\n",
    "        while q:#队列不为空时\n",
    "            for i in range(len(q)):#len(q)是树某一行的节点个数\n",
    "                cur = q.popleft()#现任节点=弹出的队首元素\n",
    "                if cur == 0: \n",
    "                    return step\n",
    "                for k in range(1,int(n**0.5)+1):#从1到(n**0.5)开始遍历，k*k = 1～n\n",
    "                    child = cur - k*k#子节点=现任节点-k*k\n",
    "                    if child not in seen:#子节点没有在集合中，没被访问过，则将子节点存入队列和集合中\n",
    "                        seen.add(child)\n",
    "                        q.append(child)#子节点加入队列中，该行有几个子结点则存入几个\n",
    "            step += 1\n",
    "        return step\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        from collections import deque\n",
    "        deq=deque()\n",
    "        visited=set()\n",
    "        \n",
    "        deq.append((n,0))\n",
    "        while deq:\n",
    "            number, step = deq.popleft()\n",
    "            targets = [number -i*i for i in range(1,int(n**0.5)+1)]\n",
    "            for target in targets:\n",
    "                if target == 0:\n",
    "                    return step + 1\n",
    "                if target not in visited:\n",
    "                    deq.append((target,step+1))\n",
    "                    visited.add(target)\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        m = int(sqrt(n))\n",
    "        d = {}\n",
    "        for i in range(1, m + 1):\n",
    "            d[i*i] = 1\n",
    "        if n in d:\n",
    "            return 1\n",
    "        def mix_2(a1, a2, k):\n",
    "            new_a = {}\n",
    "            for i in a1:\n",
    "                for j in a2:\n",
    "                    new_a[i + j] = k\n",
    "            return new_a\n",
    "        k = 1\n",
    "        d1 = d\n",
    "        while True:\n",
    "            k +=1\n",
    "            d1 = mix_2(d, d1, k)\n",
    "            if n in d1:\n",
    "                return k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        data={}\n",
    "        for i in range(1,101):\n",
    "            data[i*i]=True\n",
    "        temp={}\n",
    "        temp[0]=True\n",
    "        res=0\n",
    "        while True:\n",
    "            res+=1\n",
    "            c={}\n",
    "            for i in temp.keys():\n",
    "                for j in data.keys():\n",
    "                    if i+j==n:\n",
    "                        return res\n",
    "                    c[i+j]=True\n",
    "            temp=c\n",
    "            \n",
    "                       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        result = [0,1,2,3,1,2,3,4,2,1,2,3,3,2,3,4,1,2,2,3,2,3,3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,4,3,3,2,3,4,3,3,4,2,3,3,3,2,3,3,4,3,2,2,3,3,2,3,4,3,3,2,3,3,2,3,4,3,3,3,3,4,3,3,4,2,3,3,3,3,2,3,4,2,1,2,3,3,2,3,4,2,2,2,3,3,3,3,4,3,2,2,3,4,3,3,4,3,3,2,3,3,2,3,4,2,2,3,3,3,2,3,4,4,2,3,3,3,3,3,4,3,3,2,3,4,3,3,4,3,2,3,3,2,3,3,4,2,2,2,3,3,3,3,4,2,2,2,3,3,3,3,4,3,2,2,3,4,3,3,4,3,3,3,3,2,2,3,4,2,3,2,3,3,2,3,4,3,3,3,3,2,3,3,4,3,3,2,3,4,3,3,4,3,3,2,3,3,2,3,4,2,2,3,3,3,3,3,4,3,3,2,3,3,2,3,4,3,2,2,3,4,2,3,4,3,2,3,3,3,3,3,4,3,3,2,3,3,2,3,4,4,3,2,3,2,2,3,4,3,3,3,3,4,2,3,4,4,2,2,3,3,3,3,4,2,3,3,3,3,2,3,4,1]\n",
    "        return result[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        cands = [i ** 2 for i in range(1, int((n ** 0.5)//1) + 1)]\n",
    "        from collections import deque\n",
    "        que = deque([(n, 0)])\n",
    "        visited = set(())\n",
    "\n",
    "        while que:\n",
    "            curr, step = que.popleft()\n",
    "            if curr == 0:\n",
    "                return step\n",
    "            else:\n",
    "                for c in cands:\n",
    "                    if curr - c not in visited:\n",
    "                        que.append((curr - c, step + 1))\n",
    "                    visited.add(curr - c)\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        return [0, 1, 2, 3, 1, 2, 3, 4, 2, 1, 2, 3, 3, 2, 3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3, 2, 3, 4, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 2, 2, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 3, 2, 2, 3, 4, 2, 3, 4, 3, 2, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 4, 3, 2, 3, 2, 2, 3, 4, 3, 3, 3, 3, 4, 2, 3, 4, 4, 2, 2, 3, 3, 3, 3, 4, 2, 3, 3, 3, 3, 2, 3, 4, 1][n]\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        ans = [0, 1, 2, 3, 1, 2, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 3, 1, 2, 3, 4, 2, 3, 4, 2, 3, 2, 3, 1, 2, 3, 4, 2, 2, 3, 3, 3, 2, 3, 4, 3, 1, 2, 3, 2, 2, 3, 4, 3, 3, 2, 3, 4, 2, 3, 4, 1, 2, 3, 3, 2, 3, 3, 4, 2, 2, 2, 3, 3, 3, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 3, 2, 2, 3, 1, 2, 3, 4, 2, 3, 2, 3, 3, 2, 3, 4, 4, 2, 3, 3, 2, 2, 3, 4, 3, 1, 2, 3, 4, 2, 3, 4, 2, 3, 2, 3, 3, 3, 3, 4, 2, 2, 3, 3, 3, 3, 3, 4, 1, 2, 2, 3, 2, 2, 3, 4, 3, 2, 3, 3, 4, 2, 3, 4, 2, 3, 2, 3, 2, 3, 3, 4, 3, 1, 2, 3, 3, 2, 3, 4, 3, 3, 2, 3, 2, 2, 3, 4, 3, 2, 3, 3, 4, 3, 3, 4, 3, 2, 2, 3, 1, 2, 3, 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, 3, 3, 4, 2, 3, 3, 3, 2, 3, 3, 4, 3, 2, 2, 3, 3, 2, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 3, 3, 3, 3, 4, 3, 3, 4, 2, 3, 3, 3, 3, 2, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 2, 2, 2, 3, 3, 3, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 2, 2, 3, 3, 3, 2, 3, 4, 4, 2, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 4, 3, 3, 4, 3, 2, 3, 3, 2, 3, 3, 4, 2, 2, 2, 3, 3, 3, 3, 4, 2, 2, 2, 3, 3, 3, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 3, 3, 3, 3, 2, 2, 3, 4, 2, 3, 2, 3, 3, 2, 3, 4, 3, 3, 3, 3, 2, 3, 3, 4, 3, 3, 2, 3, 4, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 2, 2, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 3, 2, 2, 3, 4, 2, 3, 4, 3, 2, 3, 3, 3, 3, 3, 4, 3, 3, 2, 3, 3, 2, 3, 4, 4, 3, 2, 3, 2, 2, 3, 4, 3, 3, 3, 3, 4, 2, 3, 4, 4, 2, 2, 3, 3, 3, 3, 4, 2, 3, 3, 3, 3, 2, 3, 4, 1]\n",
    "        return ans[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        # 妈的打表\n",
    "        dp=[0,1,2,3,1,2,3,4,2,1,2,3,3,2,3,4,1,2,2,3,2,3,3,4,3,1,2,3,4,2,3,4,2,3,2,3,1,2,3,4,2,2,3,3,3,2,3,4,3,1,2,3,2,2,3,4,3,3,2,3,4,2,3,4,1,2,3,3,2,3,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3,4,2,1,2,3,3,2,3,4,2,2,2,3,3,3,3,4,3,2,2,3,4,3,3,4,3,3,2,3,3,2,3,4,2,2,3,3,3,2,3,4,4,2,3,3,3,3,3,4,3,3,2,3,4,3,3,4,3,2,3,3,2,3,3,4,2,2,2,3,3,3,3,4,2,2,2,3,3,3,3,4,3,2,2,3,4,3,3,4,3,3,3,3,2,2,3,4,2,3,2,3,3,2,3,4,3,3,3,3,2,3,3,4,3,3,2,3,4,3,3,4,3,3,2,3,3,2,3,4,2,2,3,3,3,3,3,4,3,3,2,3,3,2,3,4,3,2,2,3,4,2,3,4,3,2,3,3,3,3,3,4,3,3,2,3,3,2,3,4,4,3,2,3,2,2,3,4,3,3,3,3,4,2,3,4,4,2,2,3,3,3,3,4,2,3,3,3,3,2,3,4,1]\n",
    "        return dp[n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        if n in [0, 1]:\n",
    "            return n\n",
    "\n",
    "        nums = []\n",
    "        i = 1\n",
    "        while i**2 <= n:\n",
    "            nums.append(i**2)\n",
    "            i += 1 \n",
    "\n",
    "        dp = [[float(\"inf\")]*(n+1) for _ in range(len(nums)+1)]\n",
    "\n",
    "        for i in range(1, len(nums)+1):\n",
    "            for j in range(n+1):\n",
    "                if j == 0:\n",
    "                    dp[i][j] = 0\n",
    "                else:\n",
    "                    if nums[i-1] <= j:\n",
    "                        dp[i][j] = min(dp[i-1][j], dp[i][j-nums[i-1]]+1)\n",
    "                    else:\n",
    "                        dp[i][j] = dp[i-1][j]\n",
    "        return dp[-1][-1] if dp[-1][-1] != float(\"inf\") else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        nums = int(math.sqrt(n))\n",
    "        dp = [[100]*(n+1) for i in range(nums+1)]\n",
    "        dp[0][0] = 0\n",
    "        for i in range(1, nums+1):\n",
    "            m = i ** 2\n",
    "            for j in range(n+1):\n",
    "                if j<m:\n",
    "                    dp[i][j] = dp[i-1][j]\n",
    "                else:\n",
    "                    dp[i][j] = min(dp[i-1][j], dp[i-1][j-m] + 1, dp[i][j-m] + 1)\n",
    "\n",
    "        return dp[-1][-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        def isSquares(n):\n",
    "            q=int(math.sqrt(n))\n",
    "            return q\n",
    "        l=[i*i for i in range(isSquares(n)+1,0,-1)]\n",
    "        print(l)\n",
    "        dp = [[n+1] * (n+1) for _ in range(len(l)+1)]    # 初始化为一个较大的值，如 +inf 或 amount+1\n",
    "        # 合法的初始化\n",
    "        dp[0][0] = 0    # 其他 dp[0][j]均不合法\n",
    "\n",
    "\n",
    "        # 完全背包：优化后的状态转移\n",
    "        for i in range(1, len(l)+1):             # 第一层循环：遍历硬币\n",
    "            for j in range(n+1):       # 第二层循环：遍历背包\n",
    "                if j < l[i-1]:          # 容量有限，无法选择第i种硬币\n",
    "                    dp[i][j] = dp[i-1][j]\n",
    "                else:                       # 可选择第i种硬币\n",
    "                    dp[i][j] = min( dp[i-1][j], dp[i][j-l[i-1]] + 1 )\n",
    "\n",
    "        ans = dp[len(l)][n] \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        nums = []\n",
    "        i = 1\n",
    "        while i * i <= n:\n",
    "            nums.append(i * i)\n",
    "            i += 1\n",
    "        \n",
    "        length = len(nums)\n",
    "        dp = [[n+1] * (n+1) for _ in range(length+1)]\n",
    "        # dp[i][j]:从前i个完全平方数中选若干个使其和为n的所需最少完全平方数的个数（完全背包）\n",
    "        dp[0][0] = 0\n",
    "        for i in range(1, length+1):\n",
    "            for j in range(n+1):\n",
    "                if j < nums[i-1]:\n",
    "                    dp[i][j] = dp[i-1][j]\n",
    "                else:\n",
    "                    dp[i][j] = min(dp[i-1][j], dp[i][j-nums[i-1]]+1)\n",
    "        \n",
    "        ans = dp[length][n]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        m = math.floor(math.sqrt(n))\n",
    "        nums = [i ** 2 for i in range(1, m+1)]\n",
    "        f = [[0] * (n+1) for _ in range(m)]\n",
    "        for j in range(n+1):\n",
    "            f[0][j] = j\n",
    "        for i in range(1, m):\n",
    "            for j in range(1, n+1):\n",
    "                num = nums[i]\n",
    "                if j - num >= 0:\n",
    "                    f[i][j] = min(f[i][j - num] + 1, f[i-1][j])\n",
    "                else:\n",
    "                    f[i][j] = f[i-1][j]\n",
    "        return f[m-1][n]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
